package com.creawor.hz_market.t_department;

import java.util.List;
import java.util.Map;

import net.sf.hibernate.HibernateException;

import com.creawor.imei.base.Common_qry_QueryMap;

public class DepartmentManager {

	private static final String SELECT_ALL_DEPARTMENT = "select * from department";

	public List findAllDepartment() {
		List alld = null;
		try {
			Common_qry_QueryMap query_map0 = new Common_qry_QueryMap();
			alld = query_map0.findAll(SELECT_ALL_DEPARTMENT + " order by id ");
		} catch (HibernateException e) {
			
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return alld;
	}

	public Map findAllDepartmentByid(int id) {
		Map map = null;
		List alld = null;
		try {
			Common_qry_QueryMap query_map0 = new Common_qry_QueryMap();
			alld = query_map0
					.findAll(SELECT_ALL_DEPARTMENT + " where id=" + id);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (alld != null && alld.size() > 0) {
			map = (Map) alld.get(0);
		}
		return map;
	}

	public Map findAllDepartmentByname(String name) {
		Map map = null;
		List alld = null;
		try {
			Common_qry_QueryMap query_map0 = new Common_qry_QueryMap();
			alld = query_map0.findAll(SELECT_ALL_DEPARTMENT
					+ " where department='" + name + "'");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (alld != null && alld.size() > 0) {
			map = (Map) alld.get(0);
		}
		return map;
	}

	public String findAllDepartmentNameStr() {
		StringBuffer str = new StringBuffer("");
		List all = findAllDepartment();

		if (all != null) {
			for (int i = 0; i < all.size(); i++) {
				Map map = (Map) all.get(i);
				if (i != 0) {
					str.append(",");
				}
				str.append((String) map.get("department"));
			}
		}
		return str.toString();
	}
	public static void main(String[] arg0){
		DepartmentManager dp = new DepartmentManager();
		System.out.println(dp.findAllDepartment());
	}

}
